
package com.lmx.persistence.service;

import com.lmx.common.constants.ICommonConstants;
import com.lmx.common.context.ActionContextHolder;
import com.lmx.common.util.HttpRequestUtil;
import com.lmx.repoDomain.tmodel.Call;
import com.lmx.repoDomain.tmodel.Dicttype;
import com.querydsl.core.types.dsl.BooleanExpression;
import com.querydsl.core.types.dsl.PathBuilder;
import com.querydsl.jpa.impl.JPAQuery;
import net.sf.json.JSONObject;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Scope;
import org.springframework.stereotype.Service;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Map;


/**
 * 服务启动时初始化数据
 *
 * @author Administrator
 * @version 1.00
 */
@Service
@Scope("prototype")
public class StartupInitDataService<T>{
    private Log logger = LogFactory.getLog(this.getClass());

    @PersistenceContext
    private EntityManager em;

    @Autowired
    protected GenericService dslJpaService;

    /**
     * 初始化字典表数据
     */
    public void initDicttype(){
        PathBuilder<?> builder = new PathBuilder<Dicttype>(Dicttype.class, "dicctype");
        JPAQuery query=new JPAQuery(em);
        ArrayList<Dicttype> dicttypes= (ArrayList<Dicttype>)query.from(builder).fetch();
        Map<String ,Dicttype > map = new HashMap<String,Dicttype>();
        for (int i = 0; i < dicttypes.size(); i++) {
            map.put(dicttypes.get(i).getTypecode(),dicttypes.get(i));
        }
        ActionContextHolder.setDicctypeHolder(map);
        logger.debug("初始化字典数据完成");
    }




}
